package Ctr;

import java.util.ArrayList;

import Model.Partorder;
import Model.Salesorder;
import DB.DBCustomer;
import DB.DBInvoice;
import DB.DBPartorder;
import DB.DBSalesorder;

/*
 * @author Jan
 */
public class CtrSalesorder {
	
	private DBSalesorder dbs;
	private DBPartorder dbp;
	 
	public CtrSalesorder()
	{
		dbs = new DBSalesorder();
		dbp = new DBPartorder();
	}
	
	public boolean updateSalesorder(String id, String salesorderDate, String delStatus, String delDate, String invoice, String custId)
	{
		boolean succes = false;
		
		if(dbs.deleteSalesorder(id))
		{
			DBCustomer dbc = new DBCustomer();
			DBInvoice dbi = new DBInvoice();
			Salesorder sales = new Salesorder(id, salesorderDate, delStatus, delDate, dbi.getInvoice(invoice), dbc.getCustomer(custId));
			if(dbs.addSalesorder(sales))
			{
				succes = true;
			}
		}
		
		return succes;
	}
	
	public Salesorder getSalesorder(String id)
	{
		return dbs.getSalesorder(id);
	}
	
	public ArrayList<Salesorder> getAllSalesorders()
	{
		return dbs.getAllSalesorders();
	}
	
	public void addSalesorder(Salesorder salesorder)
	{
		dbs.addSalesorder(salesorder);
	}
	
	public void deleteSalesorder(String salesorderId)
	{
		dbs.deleteSalesorder(salesorderId);
	}
	
	public ArrayList<Partorder> getAllPartorders(String salesorderID)
	{
		DBPartorder dbp = new DBPartorder();
		return dbp.getAllPartorders(salesorderID);
	}
	
	public void addPartorder(Partorder partorder)
	{
		dbp.addPartorder(partorder);
	}
	
	public void deletePartorder(String partorderID)
	{
		dbp.deleteSalesorder(partorderID);
	}
}
